package com.rmi.spring.client;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;

public class RemoteFactoryBean implements FactoryBean<Object> {
	private Class<?> interfaceClass;
	private String serviceUrl;
	
	public RemoteFactoryBean(Class<?> interfaceClass, String serviceUrl) {
		super();
		this.interfaceClass = interfaceClass;
		this.serviceUrl = serviceUrl;
	}

	@Override
	public Object getObject() throws Exception {
		RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
		rmiProxyFactoryBean.setServiceUrl(serviceUrl);
		rmiProxyFactoryBean.setServiceInterface(interfaceClass);
		rmiProxyFactoryBean.afterPropertiesSet();
		return rmiProxyFactoryBean.getObject();
	}

	@Override
	public Class<?> getObjectType() {
		return interfaceClass;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	
}